//
//  ZYLiveNSObject.m
//
//  Created by Yeewii@hotmail com on 16/6/29
//  Copyright (c) 2016 __MyCompanyName__. All rights reserved.
//

#import "ZYLiveNSObject.h"
#import "ZYLiveT1462958418713.h"


NSString *const kZYLiveNSObjectT1462958418713 = @"T1462958418713";


@interface ZYLiveNSObject ()

- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;

@end

@implementation ZYLiveNSObject

@synthesize t1462958418713 = _t1462958418713;


+ (instancetype)modelObjectWithDictionary:(NSDictionary *)dict
{
    return [[self alloc] initWithDictionary:dict];
}

- (instancetype)initWithDictionary:(NSDictionary *)dict
{
    self = [super init];
    
    // This check serves to make sure that a non-NSDictionary object
    // passed into the model class doesn't break the parsing.
    if(self && [dict isKindOfClass:[NSDictionary class]]) {
    NSObject *receivedZYLiveT1462958418713 = [dict objectForKey:kZYLiveNSObjectT1462958418713];
    NSMutableArray *parsedZYLiveT1462958418713 = [NSMutableArray array];
    if ([receivedZYLiveT1462958418713 isKindOfClass:[NSArray class]]) {
        for (NSDictionary *item in (NSArray *)receivedZYLiveT1462958418713) {
            if ([item isKindOfClass:[NSDictionary class]]) {
                [parsedZYLiveT1462958418713 addObject:[ZYLiveT1462958418713 modelObjectWithDictionary:item]];
            }
       }
    } else if ([receivedZYLiveT1462958418713 isKindOfClass:[NSDictionary class]]) {
       [parsedZYLiveT1462958418713 addObject:[ZYLiveT1462958418713 modelObjectWithDictionary:(NSDictionary *)receivedZYLiveT1462958418713]];
    }

    self.t1462958418713 = [NSArray arrayWithArray:parsedZYLiveT1462958418713];

    }
    
    return self;
    
}

- (NSDictionary *)dictionaryRepresentation
{
    NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
    NSMutableArray *tempArrayForT1462958418713 = [NSMutableArray array];
    for (NSObject *subArrayObject in self.t1462958418713) {
        if([subArrayObject respondsToSelector:@selector(dictionaryRepresentation)]) {
            // This class is a model object
            [tempArrayForT1462958418713 addObject:[subArrayObject performSelector:@selector(dictionaryRepresentation)]];
        } else {
            // Generic object
            [tempArrayForT1462958418713 addObject:subArrayObject];
        }
    }
    [mutableDict setValue:[NSArray arrayWithArray:tempArrayForT1462958418713] forKey:kZYLiveNSObjectT1462958418713];

    return [NSDictionary dictionaryWithDictionary:mutableDict];
}

- (NSString *)description 
{
    return [NSString stringWithFormat:@"%@", [self dictionaryRepresentation]];
}

#pragma mark - Helper Method
- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict
{
    id object = [dict objectForKey:aKey];
    return [object isEqual:[NSNull null]] ? nil : object;
}


#pragma mark - NSCoding Methods

- (id)initWithCoder:(NSCoder *)aDecoder
{
    self = [super init];

    self.t1462958418713 = [aDecoder decodeObjectForKey:kZYLiveNSObjectT1462958418713];
    return self;
}

- (void)encodeWithCoder:(NSCoder *)aCoder
{

    [aCoder encodeObject:_t1462958418713 forKey:kZYLiveNSObjectT1462958418713];
}

- (id)copyWithZone:(NSZone *)zone
{
    ZYLiveNSObject *copy = [[ZYLiveNSObject alloc] init];
    
    if (copy) {

        copy.t1462958418713 = [self.t1462958418713 copyWithZone:zone];
    }
    
    return copy;
}


@end
